
/*结构体定义*/
typedef struct qnode
{
	ElemType data;
	struct qnode *next;
}qnode,*queue_ptr;

typedef struct 
{
	queue_ptr front;//对头指针
	queue_ptr rear;//队尾指针
}link_queue;

/*队列初始化*/
void queue_init(link_queue *q)
{
	q->front = q->rear = (queue_ptr)malloc(sizeof(qnode));//引入头节点
	if(!q->front || !->rear)
	{
		printf("队列节点空间分配失败!\n");
		exit(0)
	}
	q->front->next = NULL;
}

/*入队*/
void insert_queue(link_queue *q,ElemType e)
{
	queue_ptr p;
	p = (queue_ptr)malloc(sizeof(qnode));
	if(!p)
	{
		printf("对列新结点空间分配失败!\n");
		exit(0);
	}
	p->data = e;
	p->next = NULL;
	q->rear->next = p;
	q->rear = p;
}

/*出队*/
void delete_queue(link_queue *q,ElemType *e)
{
	queue_ptr p;
	
	/*队列为空,直接返回*/
	if(q->friont = q->rear)
	{
		printf("队列为空!\n");
		return;
	}
	
	p = q->front->next;
	*e = p->data;
	q->front->next = p->next;
	
	/*若队列中只有一个结点*/
	if(q->rear == p)
	{
		q->rear = q->front;
	}
	
	free(p);
	
}

/*销毁队列*/
void distory_queue(link_queue *q)
{
	while(q->front)
	{
		q->rear = q->front->next;//从第一个结点开始往后销毁
		free(q->front);
		q->front = q->rear;
	}
}



